import java.io.*;
import java.util.*;

public class Main {
    private static final double MAX_SCORE = 200.0;
    private static final double SCORE_OF_BASLINE = 200.0 * 0.6;

    public static void main(String[] args) throws FileNotFoundException {
        String mode = "GEN_SCH_SCORE";
        if (mode.contains("GEN_SCH_SCORE")) {
            String scorePath = "./final_score.txt";
            PrintStream out = new PrintStream(new FileOutputStream(scorePath));
            System.setOut(out);
            int nTests = 20;
            double totalScore = 0;
            List<Double> scoreList = new ArrayList<>();
            for (int i = 1; i <= nTests; i++) {
                System.err.print("test case #" + i + ": ");
                InteractiveSystem interSys = new InteractiveSystem();
                String filePath = "./data/" + i + ".in";
                interSys.init(filePath);
                int res = interSys.getNumOfMachines();
                filePath = "./data/baseline_" + i + ".out";
                Scanner scanner = new Scanner(new File(filePath));
                int baseline = scanner.nextInt();
                double score = 0.0;
                if (res != -1) {
                    score = Math.min(MAX_SCORE, 1.0 * baseline / res * SCORE_OF_BASLINE);
                }
                scoreList.add(score);
                totalScore += score;
                System.err.println(String.format("%.2f", score));
            }
            System.err.println("Final Score: " + String.format("%.2f", totalScore / scoreList.size()));
            System.out.println("Final Score: " + String.format("%.2f", totalScore / scoreList.size()));
            for (int i = 0; i < scoreList.size(); i++) {
                System.out.println("Score of Test Case #" + (i + 1) + ": " + String.format("%.2f", scoreList.get(i)));
            }
        }
    }
}

class InteractiveSystem {
    private int n;
    private int totalVcpu;
    private int totalMem;
    private int numOfIns;
    private List<Integer> usedVcpu;
    private List<Integer> usedMem;
    private List<Integer> idToPos;
    private List<Integer> idToVcpu;
    private List<Integer> idToMem;
    private Scheduler scheduler;
    Scanner scanner;

    private static final int[] NUM_OF_EXPAND = {0, 100};
    private static final int MAX_OF_PHY_MAC = 100000;

    public InteractiveSystem() {
        scheduler = new Scheduler();
        usedVcpu = new ArrayList<>();
        usedMem = new ArrayList<>();
        idToPos = new ArrayList<>();
        idToVcpu = new ArrayList<>();
        idToMem = new ArrayList<>();
    }

    public void addVM(int id, int vcpu, int mem) {
        assert id == idToPos.size();
        idToPos.add(-1);
        idToVcpu.add(vcpu);
        idToMem.add(mem);
    }

    public boolean create(int id, int pos, int vcpu, int mem) {
        if (pos < 0 || pos >= usedVcpu.size()) {
            return false;
        }
        if (usedVcpu.get(pos) + vcpu > totalVcpu || usedMem.get(pos) + mem > totalMem) {
            return false;
        }
        idToPos.set(id, pos);
        usedVcpu.set(pos, usedVcpu.get(pos) + vcpu);
        usedMem.set(pos, usedMem.get(pos) + mem);
        return true;
    }

    public void remove(int id) {
        int pos = idToPos.get(id);
        int vcpu = idToVcpu.get(id);
        int mem = idToMem.get(id);
        usedVcpu.set(pos, usedVcpu.get(pos) - vcpu);
        usedMem.set(pos, usedMem.get(pos) - mem);
    }

    public void init(String filePath) throws FileNotFoundException {
        scanner = new Scanner(new File(filePath));
        n = scanner.nextInt();
        totalVcpu = scanner.nextInt();
        totalMem = scanner.nextInt();
        numOfIns = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            usedVcpu.add(0);
        }
        usedMem = new ArrayList<>(Collections.nCopies(n, 0));
        scheduler.init(n, totalVcpu, totalMem);
    }

    public boolean runOnce() {
        String insName = scanner.next();
        int id = scanner.nextInt();
        boolean isSuccess = true;
        if (insName.charAt(0) == 'C') {
            int vcpu = scanner.nextInt();
            int mem = scanner.nextInt();
            Pair<Integer, Integer> res = scheduler.create(id, vcpu, mem);
            if (res.getSecond() < NUM_OF_EXPAND[0] || res.getSecond() > NUM_OF_EXPAND[1]) {
                return false;
            }
            int pos = res.getFirst();
            for (int i = 0; i < res.getSecond(); i++) {
                n++;
                if (n > MAX_OF_PHY_MAC) {
                    return false;
                }
                usedVcpu.add(0);
                usedMem.add(0);
            }
            idToPos.add(0);
            idToVcpu.add(vcpu);
            idToMem.add(mem);
            isSuccess = create(id, pos, vcpu, mem);
        } else {
            scheduler.remove(id);
            remove(id);
        }
        return isSuccess;
    }

    public int getNumOfMachines() throws FileNotFoundException {
        boolean isSuccess = true;
        for (int i = 0; i < numOfIns; i++) {
            if (!runOnce()) {
                isSuccess = false;
                break;
            }
        }
        return isSuccess ? usedVcpu.size() : -1;
    }
}